import random
# 排序(从小到大)
from typing import List
#冒泡排序
def sortArray1(nums: List[int]):
    for i in range(len(nums)-1):
        for j in range(len(nums)-1-i):
            if nums[j]>nums[j+1]:
                nums[j],nums[j+1]=nums[j+1],nums[j]

#插入排序
def sortArray2(nums: List[int]):
    for i in range(len(nums)):
        temp=nums[i]#要摸的牌
        j=i-1#手上的牌
        while j>=0 and nums[j]>temp:
            nums[j+1]=nums[j]
            j-=1
        nums[j+1]=temp
    return nums

# 选择排序
def sortArray3(nums: List[int]):
    for i in range(len(nums)-1):
        min_loc=i
        for j in range(i+1,len(nums)):
            if nums[j]<nums[min_loc]:
                min_loc=j
        if min_loc!=i:
            nums[min_loc],nums[i]=nums[i],nums[min_loc]
    return nums

if __name__=="__main__":
    A = [random.randint(0,100) for i in range(0,10)]
    B = [random.randint(0,100) for i in range(0,10)]
    C = [random.randint(0,100) for i in range(0,10)]

    print("A:",A,end=" ")
    sortArray1(A)
    print("冒泡排序法后 ",A)
    print("B:",B,end=" ")

    sortArray2(B)
    print("插入排序法后 ",B)

    print("C:",C,end=" ")
    sortArray3(C)
    print("选择排序法后 ",C)


